<template>
	<view>
		<view class="">
			<view class="u-b-r-20 u-p-20 bg_FFFFFF">
				<view v-if="!isTab" class="u-flex u-col-center">
					<view class=" u-font-28 u-m-r-40">抬头类型</view>
					<view @click="changeType(1)" class="u-flex u-col-center " v-if="personalshow">
						<image style="width: 38rpx;height: 38rpx; border-radius: 100%;" :src="type == 1 ?'https://www.sqkjkj.vip/wxImg/car/img2.png':'https://www.sqkjkj.vip/wxImg/car/img.png'"></image>
						<text class="u-font-28  u-weight u-m-l-20">个人</text>
					</view>
					<view @click="changeType(2)" class="u-flex u-col-center u-m-l-30" v-if="enterpriseshow">
						<image style="width: 38rpx;height: 38rpx;  border-radius: 100%;" :src="type == 1 ?'https://www.sqkjkj.vip/wxImg/car/img.png':'https://www.sqkjkj.vip/wxImg/car/img2.png'"></image>
						<text class="u-font-28  u-weight u-m-l-20">企业</text>
					</view>
				</view>
				<view class="u-m-t-20" v-if="type==1">
					<view class="u-flex u-col-center u-m-t-20">
						<view class=" u-font-28 u-w-150">名称</view>
						<view class="u-b-r-10 u-p-20" style="background: #F8F8F8;width: 70%;">
							<input v-model="models.name" type="text" placeholder="请输入名称" class="u-font-28"/>
						</view>
					</view>
					<view class="u-flex u-col-center u-m-t-20">
						<view class=" u-font-28 u-w-150">电话</view>
						<view class="u-b-r-10 u-p-20" style="background: #F8F8F8;width: 70%;">
							<input v-model="models.mobile" type="number" placeholder="请输入电话" class="u-font-28" maxlength="11"/>
						</view>
					</view>
					<!-- <view class="u-flex u-col-center u-m-t-20">
						<view class=" u-font-28 u-w-150">企业电话</view>
						<view class="u-b-r-10 u-p-20" style="background: #F8F8F8;width: 70%;">
							<input v-model="models.mobile" type="number" placeholder="请输入电话" class="u-font-28" maxlength="11"/>
						</view>
					</view> -->
					<view class="u-flex u-col-center u-m-t-20">
						<view class=" u-font-28 u-w-150">邮箱</view>
						<view class="u-b-r-10 u-p-20" style="background: #F8F8F8;width: 70%;">
							<input v-model="models.email" type="text" placeholder="请输入邮箱" class="u-font-28"/>
						</view>
					</view>
				</view>
				<view v-if="type==2">
					<view class="u-flex u-col-center u-m-t-20">
						<view class=" u-font-28 u-w-150">企业名称</view>
						<view class="u-b-r-10 u-p-20" style="background: #F8F8F8;width: 70%;">
							<input v-model="model.name" type="text" placeholder="请输入企业名称" class="u-font-28"/>
						</view>
					</view>
					<view class="u-flex u-col-center u-m-t-20">
						<view class=" u-font-28 u-w-150">企业税号</view>
						<view class="u-b-r-10 u-p-20" style="background: #F8F8F8;width: 70%;">
							<input v-model="model.tax_number" type="text" placeholder="请输入企业税号" class="u-font-28"/>
						</view>
					</view>
					<view class="u-flex u-col-center u-m-t-20">
						<view class=" u-font-28 u-w-150">开户行</view>
						<view class="u-b-r-10 u-p-20" style="background: #F8F8F8;width: 70%;">
							<input v-model="model.bank" type="text" placeholder="请输入开户行" class="u-font-28"/>
						</view>
					</view>
					
					<view class="u-flex u-col-center u-m-t-20">
						<view class=" u-font-28 u-w-150">银行账号</view>
						<view class="u-b-r-10 u-p-20" style="background: #F8F8F8;width: 70%;">
							<input v-model="model.bank_number" type="text" placeholder="请输入银行账号" class="u-font-28"/>
						</view>
					</view>
					<view class="u-flex u-col-center u-m-t-20">
						<view class=" u-font-28 u-w-150">企业地址</view>
						<view class="u-b-r-10 u-p-20" style="background: #F8F8F8;width: 70%;">
							<input v-model="model.address" type="text" placeholder="请输入企业地址" class="u-font-28"/>
						</view>
					</view>
					<view class="u-flex u-col-center u-m-t-20">
						<view class=" u-font-28 u-w-150">企业电话</view>
						<view class="u-b-r-10 u-p-20" style="background: #F8F8F8;width: 70%;">
							<input v-model="model.mobile" type="number" maxlength="11" placeholder="请输入企业电话" class="u-font-28"/>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="u-flex u-col-center u-row-between u-b-r-10 u-p-20 bg_FFFFFF u-m-t-20">
			<view class="u-font-26 u-weight">默认地址</view>
			<image  @click="changeType2" style="width: 38rpx;height: 38rpx;border-radius: 100%;" :src="type2 ?'https://www.sqkjkj.vip/wxImg/car/img2.png':'https://www.sqkjkj.vip/wxImg/car/img.png'"></image>
		</view> -->
		<view style="height: 160rpx;"></view>
		<view @click="submit" class="u-fixed u-w-750 u-b-0 u-z-300 u-p-25 bs_EFEFEF bg_FFFFFF">
			<view class="bg_FC3533FF u-h-80 u-l-h-80 u-text-center cl_FFF u-b-r-20" >
				提交
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>
<script>
	export default {
		data() {
			return {
				isTab:false,
				type:1,
				type2:false,
				models:{
					id:'',
					type:1,
					name:'',
					mobile:'',
					email:'',
					is_default:0
				},
				model:{
					id:'',
					name:'',
					type:2,
					tax_number:'',
					bank:'',
					bank_number:'',
					address:'',
					mobile:'',
					is_default:0
				},
				personalshow:true,//编辑信息是个人开票类型隐藏
				enterpriseshow:true,//编辑信息是企业开票类型隐藏
			}
		},
		onLoad(o){
			if(o.type=='edit'){
				this.isTab=true
			}
		},
		onShow() {
			if(uni.getStorageSync('edit_rise')){
				this.type=uni.getStorageSync('edit_rise').type
				if(this.type==1){
					this.models=uni.getStorageSync('edit_rise')
				}else{
					this.model=uni.getStorageSync('edit_rise')
				}
				uni.removeStorageSync('edit_rise')
			}
		},
		onUnload() {
			uni.removeStorageSync('edit_rise')
		},
		methods: {
			changeType(type){
				this.type = type;
			},
			changeType2(){
				this.type2 = !this.type2;
				this.model.is_default=this.type2?1:0
				this.models.is_default=this.type2?1:0
			},
			submit(){
				if(this.type==1){
					console.log(this.models)
				}else{
					console.log(this.model)
				}
				if(this.model.id || this.models.id){
					this.change_my_open()
				}else{
					this.add_open()
				}				
			},
			async add_open(){
				await this.$api.add_open(this.type==1?this.models:this.model,res => {
					if(res.data.code==1){
						
						this.$refs.uToast.show({
							title: res.data.msg,
							type: 'success',
							callback: cal => {
								uni.navigateBack()
							}
						})
					}
				})
			},
			async change_my_open(){
				await this.$api.change_my_open(this.type==1?this.models:this.model,res => {
					if(res.data.code==1){
						this.$refs.uToast.show({
							title: res.data.msg,
							type: 'success',
							callback: cal => {
								uni.navigateBack()
							}
						})
					}
				})
			}
		}
	}
</script>